#include <iostream>
#include <cmath>
#include <unordered_map>

bool is_prime(int a) {
    for (int y = 2; y <= static_cast<int>(std::sqrt(a)) + 1; y++) {
        if (a % y == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::unordered_map<std::string, std::string> sl = {
        {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"},
        {"five", "5"}, {"six", "6"}, {"seven", "7"}, {"eight", "8"}, {"nine", "9"}
    };
    std::string a0, a1, a2;
    std::size_t pos = 0;
    a0 = input.substr(pos, input.find(" ", pos) - pos);
    pos = input.find(" ", pos) + 1;
    a1 = input.substr(pos, input.find(" ", pos) - pos);
    pos = input.find(" ", pos) + 1;
    a2 = input.substr(pos);
    if (sl.find(a0) == sl.end()  || sl.find(a1) == sl.end() || sl.find(a2) == sl.end()) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }
    int a = std::stoi(sl[a0] + sl[a1] + sl[a2]);
    int f = 1;
    while (true) {
        if (is_prime(a - f)) {
            std::cout << a - f << std::endl;
            break;
        } else if (is_prime(a + f)) {
            std::cout << a + f << std::endl;
            break;
        }
        f += 1;
    }
    return 0;
}